if(NOT DEFINED filename)
    message(FATAL_ERROR "ERROR: Required variable \"filename\" not defined")
endif()
if(NOT DEFINED directory)
    message(FATAL_ERROR "ERROR: Required variable \"directory\" not defined")
endif()
if(NOT DEFINED projdir)
    message(FATAL_ERROR "ERROR: Required variable \"projdir\" not defined")
endif()

get_filename_component(filename "${filename}" ABSOLUTE)
get_filename_component(directory "${directory}" ABSOLUTE)

if(IS_DIRECTORY ${directory})
    message("Warning: Directory ${directory} has been untarred already, not overwriting.  Use 'make nuke' to eviscerate.")
else()
    execute_process(COMMAND ${CMAKE_COMMAND}
        -Dfilename=${filename}
        -Ddirectory=${directory}
        -Dtmp=${CMAKE_BINARY_DIR}
        -P ${projdir}/UntarFile.cmake
    )
    execute_process(COMMAND ${CMAKE_COMMAND}
        -E copy_directory ${directory} ${directory}.orig
    )
endif()
